Skip to content

chore: Add AsyncCloseable interface. #95

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

He-Pin
Copy link
Contributor

@He-Pin He-Pin commented Apr 1, 2025

Motivation and Context

Introduce a common interface for autocloseable.

How Has This Been Tested?

Breaking Changes

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

* Immediately closes the resource gracefully.
*/
default void close() {
this.closeGracefully().subscribe();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe the default implementation should call block

Copy link
Member

@chemicL chemicL left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the PR. I think with a few tweaks it will be a useful addition.


/**
* Begins the process of closing the resource gracefully, if there is one in progress,
* return the existing one.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that's accurate? We'd need to keep track of closing-in-progress and I am not certain we do that currently.

Copy link
Contributor Author

@He-Pin He-Pin Apr 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So you suggest we drop the :

if there is one in progress, return the existing one.

?

I think we should always return the same instance.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked the code, you are right, not all implementation return the same Mono, will drop this description.

Mono<Void> closeGracefully();

/**
* Immediately closes the resource gracefully.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The graceful close is not immediate, it kicks off asynchronously. In the cases of void return type it is a disconnected chain.

@@ -52,6 +52,7 @@ public interface McpServerTransportProvider {
* Immediately closes all the transports with connected clients and releases any
* associated resources.
*/
@Override
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method can be removed.


/**
* Immediately closes the resource gracefully.
*/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An @see #closeGracfully() javadoc entry would be useful.

Mono<Void> closeGracefully();

/**
* Closes the session and releases any associated resources.
*/
@Override
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method can be removed.

@@ -45,6 +45,7 @@ public interface McpTransport {
* needed. It should handle the graceful shutdown of any active connections.
* </p>
*/
@Override
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method can be removed

@He-Pin He-Pin force-pushed the asyncCloseable branch 2 times, most recently from c8a8746 to 66f6e35 Compare April 17, 2025 07:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants